﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace MTO.Framework.Web.Mvc
{
    public class GroupSelectList : GroupMultiSelectList
    {
        public GroupSelectList(Dictionary<string, IEnumerable> items)
            : this(items, null /* selectedValue */)
        {
        }

        public GroupSelectList(Dictionary<string, IEnumerable> items, object selectedValue)
            : this(items, null /* dataValuefield */, null /* dataTextField */, selectedValue)
        {
        }

        public GroupSelectList(Dictionary<string, IEnumerable> items, string dataValueField, string dataTextField)
            : this(items, dataValueField, dataTextField, null /* selectedValue */)
        {
        }

        public GroupSelectList(Dictionary<string, IEnumerable> items, string dataValueField, string dataTextField, object selectedValue)
            : base(items, dataValueField, dataTextField, ToEnumerable(selectedValue))
        {
            SelectedValue = selectedValue;
        }

        public object SelectedValue
        {
            get;
            private set;
        }

        private static IEnumerable ToEnumerable(object selectedValue)
        {
            return (selectedValue != null) ? new object[] { selectedValue } : null;
        }
    }
}
